import click
import logging
from services.article_processor import ArticleProcessor

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

@click.group()
def cli():
    """微信公众号文章处理工具"""
    pass

@cli.command()
@click.argument('url')
@click.option('--html-dir', default='data/articles', help='HTML文件输出目录')
@click.option('--pdf-dir', default='data/pdfs', help='PDF文件输出目录')
def process_url(url, html_dir, pdf_dir):
    """处理单个URL"""
    processor = ArticleProcessor(html_dir, pdf_dir)
    result = processor.process_url(url)
    
    click.echo("处理完成！")
    click.echo(f"HTML文件保存在: {html_dir}")
    click.echo(f"PDF文件保存在: {pdf_dir}")
    click.echo(f"共处理 {len(result['html_files'])} 个HTML文件")
    click.echo(f"共生成 {len(result['pdf_files'])} 个PDF文件")

@cli.command()
@click.argument('urls', nargs=-1)
@click.option('--html-dir', default='data/articles', help='HTML文件输出目录')
@click.option('--pdf-dir', default='data/pdfs', help='PDF文件输出目录')
def process_urls(urls, html_dir, pdf_dir):
    """批量处理多个URL"""
    processor = ArticleProcessor(html_dir, pdf_dir)
    result = processor.process_urls(list(urls))
    
    click.echo("处理完成！")
    click.echo(f"HTML文件保存在: {html_dir}")
    click.echo(f"PDF文件保存在: {pdf_dir}")
    click.echo(f"共处理 {len(result['html_files'])} 个HTML文件")
    click.echo(f"共生成 {len(result['pdf_files'])} 个PDF文件")

if __name__ == '__main__':
    cli() 